package com.roncoo.student.stu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.student.stu.entity.Lecturer;
import com.roncoo.student.stu.entity.LecturerAudit;
import com.roncoo.student.stu.entity.User;
import com.roncoo.student.stu.service.ILecturerAuditService;
import com.roncoo.student.stu.service.ILecturerService;
import com.roncoo.student.stu.service.impl.LecturerServiceImpl;
import com.roncoo.student.stu.service.impl.UserServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 审核
 * </p>
 *
 * @author jl
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/stu/lecturer-audit")
public class LecturerAuditController {

    @Resource
    private ILecturerAuditService lecturerAuditService;

    @Resource
    private LecturerServiceImpl lecturerService;

    @Resource
    private UserServiceImpl userService;



    @PostMapping("/findAll")
    public Page findAll(LecturerAudit lecturerAudit , Page page) {

        return  lecturerAuditService.finAll(lecturerAudit,page);
    }

    @GetMapping("updUser1")
    public boolean upduser(Integer uid){
        User user = new User();
        user.setUserType(2);
        user.setUid(uid);
        System.out.println(uid+"====");
        return userService.updateById(user);

    }

    /*
    * 通过id修改教师信息
    * */
    @PostMapping("/upd")
    public  Boolean upd(Lecturer lecturer){

        System.out.println(lecturer.getLecturerId());

        return lecturerService.updateById(lecturer);
    }

    /**
     * 讲师申请提交
     * @param lecturerAudit
     * @return
     */
    @PostMapping("/addAudit")
    public Boolean addAudit(LecturerAudit lecturerAudit){
        //创建时间 当前时间
        LocalDate now = LocalDate.now();
        String s = now.toString();
        lecturerAudit.setGmtCreate(s);
        //默认未审核
        lecturerAudit.setAuditStatus("0");
        //获取当前登录的用户的id
        User user = userService.getById(lecturerAudit.getLecturerUserId());
        Integer uid = user.getUid();
        System.out.println(uid);
        lecturerAudit.setLecturerUserId(user.getUid());
        lecturerAudit.setHeadImageUrl(user.getUimage());
        lecturerAudit.setLecturerEmail("265468498");
        System.out.println(lecturerAudit);
        System.out.println(lecturerAudit);
        return lecturerAuditService.save(lecturerAudit);
    }
    @PostMapping("judgeAdd")
    public boolean judgeAdd(String lecturerPhone){
        boolean user = lecturerAuditService.judgeAdd(lecturerPhone);
        return user;
    }
    @GetMapping("userPassword")
    public String qwe(LecturerAudit lecturerAudit){
        User user = userService.getById(lecturerAudit.getLecturerUserId());
        String upassword = user.getUpassword();
        return upassword;
    }
    /*
    * 审核
    * */
    @PostMapping("/shen")
    public  boolean updShen(LecturerAudit lecturerAudit){



        System.out.println(lecturerAudit);


        boolean b = lecturerAuditService.updateById(lecturerAudit);

        return b;

    }


    /*
    * 添加教师
    *
    * */

    @PostMapping("addTeacher")
    public Boolean add(LecturerAudit lecturerAudit){

        System.out.println(lecturerAudit.getLecturerUserName()+"==================================");
        System.out.println(lecturerAudit.getLecturerUserId()+"====");
        this.upduser(lecturerAudit.getLecturerUserId());
        return lecturerAuditService.addTeacher(lecturerAudit);
    }



}

